package com.la100.common.utils;

import java.util.HashMap;
import java.util.Map;

public class ResultMapUtil {
    public static Map<String, Object> genResultMap(boolean result, String code, String msg, Object data) {
        Map<String, Object> resultMap = new HashMap<String, Object>();
        resultMap.put("result", result);
        if (!StringUtils.isBank(code)) {
            resultMap.put("code", code);
        }
        if (!StringUtils.isBank(msg)) {
            resultMap.put("msg", msg);
        }
        if (data != null) {
            resultMap.put("data", data);
        }
        return resultMap;
    }

    public static Map<String, Object> genDefaultSuccessMap() {
        return genResultMap(true, null, null, null);
    }

    public static Map<String, Object> genDefaultSuccessDataMap(Object data) {
        return genResultMap(true, null, null, data);
    }

    public static Map<String, Object> genSuccessMap(String code, String msg) {
        return genResultMap(true, code, msg, null);
    }

    public static Map<String, Object> genSuccessDataMap(Object data) {
        return genResultMap(true, "", "", data);
    }

    public static Map<String, Object> genSuccessMap(String msg) {
        return genResultMap(true, null, msg, null);
    }

    public static Map<String, Object> genErrorMap(String msg) {
        return genResultMap(false, null, msg, null);
    }

    public static Map<String, Object> genErrorMap(String code, String msg) {
        return genResultMap(false, code, msg, null);
    }
}
